﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class Qualification
    {
        public void ImportList(List<Classes.Qualification> QualificationList)
        {
            var mdb = new MedregDBDataContext();

            var sSpec = new Classes.Speciality();
            var Spec = new Speciality();
            Spec.ImportList(sSpec.getSpecialityList(QualificationList));

            var sQualCat = new Classes.QualificationCategory();
            var QualCat = new QualificationCategory();
            QualCat.ImportList(sQualCat.getSertificateSpecialityList(QualificationList));


            foreach (Classes.Qualification qualification in QualificationList)
            {
                var qualification1 = new Qualification
                {
                    Category = qualification.Category.ID,
                    SertificateSpeciality = qualification.Speciality.ID,
                    Year = qualification.Year,
                    Employee = qualification.Employee.ID
                };

                IEnumerable<Qualification> query = (from cr in mdb.Qualification
                                                  where cr.Employee == qualification.Employee.ID
                                                  select cr
                                                   ).ToList();
                mdb.Qualification.DeleteAllOnSubmit(query);
                mdb.Qualification.InsertOnSubmit(qualification1);
            }
            mdb.SubmitChanges();
        }
    }
}
